<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

$lastID = UV::readInt($route->GET("lastid"));

$response = $db->getTable("select `M`.`sm_id`,`M`.`message`,`M`.`time`,`U`.`name` from `short_messages` as `M`,`users` as `U` where `M`.`sm_id` > '$lastID' and `M`.`user_id` = `U`.`user_id` order by `M`.`sm_id`");

if ($response)
{
	$answer = "[";
	for($i = 0; $i < count($response); $i++)
	{
		if (date("d.m.Y",$response[$i]['time']) == date("d.m.Y",time()))
			$time = date("H:i",$response[$i]['time']);
		else
			$time = date("H:i d.m",$response[$i]['time']);
		$answer .= "{\"id\":\"".$response[$i]['sm_id']."\",\"user\":\"".$response[$i]['name']."\",\"message\":\"".$response[$i]['message']."\",\"time\":\"".$time."\"}";
		if ($i < count($response)-1)
			$answer .= ",";
	}
	echo $answer .= "]";
}
?>